<template>
	<view class="my-search-container">
		<u-search :placeholder="placeholder" :clearabled="true" :shape="shape" height="33" :showAction='showAction'
			:inputAlign="inputAlign" v-model="keyword" margin=" 0 20rpx" :animation="true" color="#000" @search="search"
			@custom="searchBank" @clickIcon="clickIcon" @blur="blur" @clear="clear"></u-search>
	</view>
</template>

<script>
	export default {

		name: "mySearch",
		data() {
			return {
				keyword: '',
				placeholder: "请输入关键字",
				showAction: true,
				shape: "round",
				inputAlign: "center",

			}
		},
		methods: {

			goto() {
				const res = wx.getSystemInfoSync()
				if ( res.brand != undefined) {
					console.log(res.brand)
					if (this.$root.$scope.route == "subGoodsDetail/search/search") {
						return;
					}
				} else {
					console.log("5456789")
					if (this.$route.path == "/subGoodsDetail/search/search") {
						return;
					}
				}
				uni.navigateTo({
					url: `/subGoodsDetail/search/search?keyword=${this.keyword}`,
				})
			},
			// 用户确定搜索时触发，用户按回车键，或者手机键盘右下角的"搜索"键时触发
			search(val) {
			
				this.$emit("input1", val)
				this.goto()
			
		
			},
			// 用户点击右侧控件时触发
			searchBank(e) {
			
				this.$emit("input1", this.keyword)
				this.goto()

			},
			// 左侧icon点击时候时触发
			clickIcon(val) {
				console.log(val)
				this.$emit("input1", this.keyword)
				this.goto()
			},
			// 输入框失去焦点时触发
			blur() {
				// setTimeout(() => {
				// 	this.keyword = ''
				// }, 1000)
			},
			//配置了clearabled后，清空内容时会发出此事件
			clear() {

				this.$emit("input1", "true")
			}
		},

	}
</script>

<style lang="scss">
	.my-search-container {
		width: 100%;
		height: 100%;
		background-color: #c00000;
		padding: 15rpx 0;

	}
</style>